<template>
  <div class="login-container">
    <div class="login-box">
      <div class="img-box">
        <img src="../assets/img/logo.png" alt />
      </div>
      <el-form :model="loginForm" ref="loginFormRef" :rules="loginFormRules">
        <el-form-item prop="username">
          <el-input
            v-model="loginForm.username"
            prefix-icon="iconfont icon-user"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            show-password
            prefix-icon="iconfont icon-3702mima"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-row>
          <el-col :push="15">
            <el-button type="primary" @click="login">提交</el-button>
            <el-button type="info" @click=" $refs.loginFormRef.resetFields()">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
// 引入字体图标css
import '../assets/fonts/iconfont.css'
import mixin from '../mixin/index'
export default {
  mixins: [mixin],
  // 登录表单数据对象
  data () {
    return {}
  },
  methods: {
    // 登录系统
    login () {
      // this.$router.push('/home')
      this.$refs.loginFormRef.validate(async valid => {
        if (valid) {
          const { data: dt } = await this.$http.post('login', this.loginForm)
          if (dt.meta.status !== 200) {
            return this.$message.error(dt.meta.msg)
          }
          window.sessionStorage.setItem('token', dt.data.token)
          this.$message.success(dt.meta.msg)
          this.$router.push('/home')
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.login-container {
  background-color: #2b4b6b;
  height: 100%;
  overflow: hidden;
  .login-box {
    width: 450px;
    height: 304px;
    border-radius: 5px;
    background-color: #fff;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .img-box {
      width: 130px;
      height: 130px;
      border: 1px solid #eee;
      border-radius: 50%;
      background-color: #fff;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      padding: 8px;
      box-shadow: 0 0 10px #eee;
      img {
        width: 100%;
        background: #eee;
        border-radius: 50%;
      }
    }
    .el-form {
      position: absolute;
      bottom: 0;
      width: 100%;
      padding: 20px;
      box-sizing: border-box;
    }
  }
}
</style>
